﻿Module modUtil
    ''' <summary>
    ''' Transform the value X from SourceMin and SourceMax to TargetMin and TargetMax using linear algo, using Y=A*X+B
    ''' </summary>
    ''' <param name="X">Input Value</param>
    ''' <param name="SourceMin">Min Range from</param>
    ''' <param name="SourceMax">Max Range from</param>
    ''' <param name="TargetMin">Min Range to</param>
    ''' <param name="TargetMax">Min Range to</param>
    ''' <returns>Transformed value of X</returns>
    ''' <remarks></remarks>
    Public Function Map(ByVal X As Double, ByVal SourceMin As Double, ByVal SourceMax As Double, ByVal TargetMin As Double, ByVal TargetMax As Double) As Double
        Try
            'y=A*X + B
            Dim A As Double
            Dim B As Double

            A = (TargetMax - TargetMin) / (SourceMax - SourceMin)
            B = TargetMin - A * SourceMin

            Dim Y As Double
            Y = A * X + B
            Return Y
        Catch ex As Exception
            PushLog("Error in modUtil.Map: " & ex.Message)
        End Try
    End Function

    ''' <summary>
    ''' Enum function to get the RGB of color name
    ''' </summary>
    ''' <param name="ColorName">Color name as string known name</param>
    ''' <returns>Return RGB format</returns>
    ''' <remarks>colors: red, pink, blue, black, yello, brown, green, white</remarks>
    Public Function ColorName2RGB(ByVal ColorName As String) As String
        ColorName = ColorName.ToLower
        Select Case ColorName
            Case "red"
                Return "7f0000ff"
            Case "pink"
                Return "7f963eff"
            Case "blue"
                Return "7fff0000"
            Case "black"
                Return "7f000000"
            Case "yellow"
                Return "7f00ffff"
            Case "brown"
                Return "7f1e69d2"
            Case "green"
                Return "7f00ff00"
            Case "white"
                Return "7fffffff"
            Case Else
                Return "7f963eff"
        End Select
    End Function

    ''' <summary>
    ''' Future imp for debug and loggin
    ''' </summary>
    ''' <param name="Msg">Message</param>
    ''' <param name="isDebug">Debug mode or error.</param>
    ''' <remarks></remarks>
    Public Sub PushLog(ByVal Msg As String, Optional ByVal isDebug As Boolean = False)
        'Now just pop it!
        MsgBox(Msg)
    End Sub
End Module
